package com.leixiaoqiao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leixiaoqiao.mapper.UserMapper;
import com.leixiaoqiao.pojo.User;
import com.leixiaoqiao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @company: 云桥之上
 * @author: 萌萌居家好男人
 * @version: 1.0
 * @create: 2021-11-21 20:19:06
 */
@Service//IOC的注解
@Transactional//事务管理
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Boolean login(User user) {
        User one = userMapper.findOne(user);
        if (one!=null){
            return true;
        }
        return false;
    }

    @Override
    public List<User> findAll() {
        return userMapper.quaryAll();
    }

    @Override
    public PageInfo<User> getPage(Integer pageNum, Integer pageSize) {
        //1.设置分页参数,底层会将设置的参数，通过拦截查询sql执行拼接limit
        PageHelper.startPage(pageNum,pageSize);
        //2.调用查询方法
        List<User> userList = userMapper.quaryAll();
        //3.组装返回pageInfo,注意构造函数
        return new PageInfo<>(userList);
    }

    @Override
    public PageInfo<User> page(Integer pageNum, Integer pageSize) {
        //1.设置分页参数,底层会将设置的参数，通过拦截查询sql执行拼接limit
        PageHelper.startPage(pageNum,pageSize);
        //2.调用查询方法
        List<User> userList = userMapper.quaryAll();
        //3.组装返回pageInfo,注意构造函数
        return new PageInfo<>(userList);
    }

    @Override
    public Boolean add(User user) {
        int rows = userMapper.insert(user);
        if(rows > 0){
            return true;
        }
        return false;
    }

    @Override
    public User quary(Integer id) {
        return userMapper.selectOne(id);
    }
}
